package com.demo.dao;

import javax.annotation.Resource;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.demo.po.DemoBean;
@Repository
public class DemoTempDao {
	@Resource
	private JdbcTemplate jdbcTemplate;
	/**
     * 通过id获取demo对象.
     * @param id
     * @return
     */
    public DemoBean getById(String id){
       String sql = "select * from Demo where id=?";
       RowMapper<DemoBean> rowMapper = new BeanPropertyRowMapper<DemoBean>(DemoBean.class);
       return jdbcTemplate.queryForObject(sql, rowMapper,id);
    }
    public void save(DemoBean bean){
    	String sql = "insert into Demo(id,name) values(?,?)";
    	jdbcTemplate.update(sql, new Object[]{bean.getId(),bean.getName()});
    }
}
